
package com.hlkj.pay.service.merchant.impl;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hlkj.framework.common.pojo.PageResult;
import com.hlkj.framework.common.util.collection.CollectionUtils;
import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.hlkj.framework.mybatis.core.query.QueryWrapperX;
import com.hlkj.framework.mybatis.core.utils.MyBatisUtils;
import com.hlkj.pay.config.WrappersFactory;
import com.hlkj.pay.dto.merchant.*;
import com.hlkj.pay.enums.CommonEnum;
import com.hlkj.pay.enums.MerchantEnum;
import com.hlkj.pay.enums.PayEnums;
import com.hlkj.pay.infrastructure.mapper.merchant.*;
import com.hlkj.pay.infrastructure.model.merchant.*;
import com.hlkj.pay.infrastructure.model.pay.PayChannelRequestDO;
import com.hlkj.pay.service.CommonSnFilterService;
import com.hlkj.pay.service.common.IOperatedLogService;
import com.hlkj.pay.service.merchant.IMerchantAccessService;
import com.hlkj.pay.service.pay.IPayChannelService;

import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author HlpayTeam
 * @date 2024/09/25 13:33
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class MerchantAccessServiceImpl extends CommonSnFilterService implements IMerchantAccessService {

    private final MerchantAccessInfoMapper merchantAccessInfoMapper;

    private final MerchantAccessCertInfoMapper merchantAccessCertInfoMapper;

    private final MerchantAccessLicenseMapper merchantAccessLicenseMapper;

    private final MerchantAccessCardMapper merchantAccessCardMapper;

    private final MerchantAccessBusinessMapper merchantAccessBusinessMapper;

    private final IPayChannelService payChannelService;

    private final IOperatedLogService merchantAccessLogService;

    @Override
    public PageResult<MerchantAccessInfoPageDto> queryPage(MerchantAccessInfoPageQueryDto merchantAccessInfoPageQueryDto) {
        IPage<MerchantAccessInfoPageQueryDto> mpPage = MyBatisUtils.buildPage(merchantAccessInfoPageQueryDto);
        QueryWrapper<MerchantAccessInfoDO> queryWrapper = buildInfoWrapper(merchantAccessInfoPageQueryDto);
        // queryWrapper.orderByDesc("a.id");
        merchantAccessInfoMapper.selectMerchantAccessPage(mpPage, queryWrapper);
        return new PageResult(mpPage.getRecords(), mpPage.getTotal(), mpPage.getCurrent(), mpPage.getSize(), mpPage.getPages());
    }

    @Override
    public List<MerchantAccessInfoDO> queryList(MerchantAccessInfoPageQueryDto merchantAccessInfoPageQueryDto) {
        return merchantAccessInfoMapper.selectList(buildInfoWrapperX(merchantAccessInfoPageQueryDto));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long saveAccess(MerchantAccessDto merchantAccessDto) {
        // 主表
        MerchantAccessInfoDO merchantAccessInfoDO = merchantAccessDto.getMerchantAccessInfo();
        merchantAccessInfoMapper.insert(merchantAccessInfoDO);
        // 进件营业执照信息
        MerchantAccessLicenseDO merchantAccessLicenseDO = merchantAccessDto.getMerchantAccessLicense();
        // 进件法人信息
        MerchantAccessCertInfoDO merchantAccessLegalDO = merchantAccessDto.getMerchantAccessLegal();
        // 联系人信息
        MerchantAccessCertInfoDO merchantAccessContactDO = merchantAccessDto.getMerchantAccessContact();
        // 实际控制人
        MerchantAccessCertInfoDO merchantAccessControllerDO = merchantAccessDto.getMerchantAccessController();
        // 进件受益人信息
        List<MerchantAccessCertInfoDO> merchantAccessBenefits = merchantAccessDto.getMerchantAccessBenefitList();
        // 企业控股股东信息
        List<MerchantAccessCertInfoDO> merchantAccessShareholdersList = merchantAccessDto.getMerchantAccessShareholderList();
        // 经营信息
        MerchantAccessBusinessDO merchantAccessBusinessDO = merchantAccessDto.getMerchantAccessBusiness();
        // 进件结算卡信息
        MerchantAccessCardDO merchantAccessCardDO = merchantAccessDto.getMerchantAccessCard();
        if (merchantAccessLicenseDO != null) {
            merchantAccessLicenseDO.setAccessId(merchantAccessInfoDO.getId());
            merchantAccessLicenseDO.setSn(merchantAccessInfoDO.getSn());
            merchantAccessLicenseDO.setChannelCode(merchantAccessInfoDO.getChannelCode());
        }
        if (merchantAccessBusinessDO != null) {
            merchantAccessBusinessDO.setAccessId(merchantAccessInfoDO.getId());
            merchantAccessBusinessDO.setSn(merchantAccessInfoDO.getSn());
        }
        if (merchantAccessCardDO != null) {
            merchantAccessCardDO.setAccessId(merchantAccessInfoDO.getId());
            merchantAccessCardDO.setSn(merchantAccessInfoDO.getSn());
        }
        List<MerchantAccessCertInfoDO> merchantAccessCertInfoList = new ArrayList<>();
        if (merchantAccessLegalDO != null) {
            merchantAccessLegalDO.setType(MerchantEnum.CERT_INFO_TYPE.LEGAL.getCode());
            merchantAccessCertInfoList.add(merchantAccessLegalDO);
        }
        if (merchantAccessContactDO != null) {
            merchantAccessContactDO.setType(MerchantEnum.CERT_INFO_TYPE.CONTACT.getCode());
            merchantAccessCertInfoList.add(merchantAccessContactDO);
        }
        if (merchantAccessControllerDO != null) {
            merchantAccessControllerDO.setType(MerchantEnum.CERT_INFO_TYPE.CONTROLLER.getCode());
            merchantAccessCertInfoList.add(merchantAccessControllerDO);
        }
        if (merchantAccessBenefits != null) {
            merchantAccessBenefits.stream().forEach(merchantAccessCertInfoDO -> {
                merchantAccessCertInfoDO.setType(MerchantEnum.CERT_INFO_TYPE.BENEFIT.getCode());
            });
            merchantAccessCertInfoList.addAll(merchantAccessBenefits);
        }
        if (merchantAccessShareholdersList != null) {
            merchantAccessShareholdersList.stream().forEach(merchantAccessCertInfoDO -> {
                merchantAccessCertInfoDO.setType(MerchantEnum.CERT_INFO_TYPE.SHAREHOLDER.getCode());
            });
            merchantAccessCertInfoList.addAll(merchantAccessShareholdersList);
        }
        if (CollectionUtils.isNotEmpty(merchantAccessCertInfoList)) {
            merchantAccessCertInfoList.stream().forEach(merchantAccessBenefitDO -> {
                merchantAccessBenefitDO.setAccessId(merchantAccessInfoDO.getId());
                merchantAccessBenefitDO.setSn(merchantAccessInfoDO.getSn());
            });
        }
        if (merchantAccessLicenseDO != null) {
            merchantAccessLicenseMapper.insert(merchantAccessLicenseDO);
        }
        merchantAccessCardMapper.insert(merchantAccessCardDO);
        if (CollectionUtils.isNotEmpty(merchantAccessCertInfoList)) {
            merchantAccessCertInfoMapper.insertBatch(merchantAccessCertInfoList);
        }
        merchantAccessBusinessMapper.insert(merchantAccessBusinessDO);
        return merchantAccessInfoDO.getId();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long updateAccess(MerchantAccessDto merchantAccessDto) {
        // 主表
        MerchantAccessInfoDO merchantAccessInfoDO = merchantAccessDto.getMerchantAccessInfo();
        merchantAccessInfoMapper.updateById(merchantAccessInfoDO);
        // 进件营业执照信息
        MerchantAccessLicenseDO merchantAccessLicenseDO = merchantAccessDto.getMerchantAccessLicense();
        // 进件法人信息
        MerchantAccessCertInfoDO merchantAccessLegalDO = merchantAccessDto.getMerchantAccessLegal();
        // 联系人信息
        MerchantAccessCertInfoDO merchantAccessContactDO = merchantAccessDto.getMerchantAccessContact();
        // 实际控制人
        MerchantAccessCertInfoDO merchantAccessControllerDO = merchantAccessDto.getMerchantAccessController();
        // 进件受益人信息
        List<MerchantAccessCertInfoDO> merchantAccessBenefits = merchantAccessDto.getMerchantAccessBenefitList();
        // 企业控股股东信息
        List<MerchantAccessCertInfoDO> merchantAccessShareholdersList = merchantAccessDto.getMerchantAccessShareholderList();
        // 经营信息
        MerchantAccessBusinessDO merchantAccessBusinessDO = merchantAccessDto.getMerchantAccessBusiness();
        // 进件结算卡信息
        MerchantAccessCardDO merchantAccessCardDO = merchantAccessDto.getMerchantAccessCard();
        if (merchantAccessLicenseDO != null) {
            merchantAccessLicenseDO.setAccessId(merchantAccessInfoDO.getId());
            merchantAccessLicenseDO.setSn(merchantAccessInfoDO.getSn());
            merchantAccessLicenseDO.setChannelCode(merchantAccessInfoDO.getChannelCode());
        }
        if (merchantAccessBusinessDO != null) {
            merchantAccessBusinessDO.setAccessId(merchantAccessInfoDO.getId());
            merchantAccessBusinessDO.setSn(merchantAccessInfoDO.getSn());
        }
        if (merchantAccessCardDO != null) {
            merchantAccessCardDO.setAccessId(merchantAccessInfoDO.getId());
            merchantAccessCardDO.setSn(merchantAccessInfoDO.getSn());
        }
        List<MerchantAccessCertInfoDO> merchantAccessCertInfoList = new ArrayList<>();
        if (merchantAccessLegalDO != null) {
            merchantAccessLegalDO.setType(MerchantEnum.CERT_INFO_TYPE.LEGAL.getCode());
            merchantAccessCertInfoList.add(merchantAccessLegalDO);
        }
        if (merchantAccessContactDO != null) {
            merchantAccessContactDO.setType(MerchantEnum.CERT_INFO_TYPE.CONTACT.getCode());
            merchantAccessCertInfoList.add(merchantAccessContactDO);
        }
        if (merchantAccessControllerDO != null) {
            merchantAccessControllerDO.setType(MerchantEnum.CERT_INFO_TYPE.CONTROLLER.getCode());
            merchantAccessCertInfoList.add(merchantAccessControllerDO);
        }
        if (merchantAccessBenefits != null) {
            merchantAccessBenefits.stream().forEach(benefit -> {
                benefit.setType(MerchantEnum.CERT_INFO_TYPE.BENEFIT.getCode());
            });
            merchantAccessCertInfoList.addAll(merchantAccessBenefits);
        }
        if (merchantAccessShareholdersList != null) {
            merchantAccessShareholdersList.stream().forEach(shareholder -> {
                shareholder.setType(MerchantEnum.CERT_INFO_TYPE.SHAREHOLDER.getCode());
            });
            merchantAccessCertInfoList.addAll(merchantAccessShareholdersList);
        }
        if (CollectionUtils.isNotEmpty(merchantAccessCertInfoList)) {
            merchantAccessCertInfoList.stream().forEach(merchantAccessCertInfoDO -> {
                merchantAccessCertInfoDO.setAccessId(merchantAccessInfoDO.getId());
                merchantAccessCertInfoDO.setSn(merchantAccessInfoDO.getSn());
            });
        }
        if (merchantAccessLicenseDO != null) {
            merchantAccessLicenseMapper.update(merchantAccessLicenseDO, WrappersFactory.updateWithNullField(merchantAccessLicenseDO).eq(MerchantAccessLicenseDO::getAccessId,merchantAccessInfoDO.getId()));
        }
        merchantAccessCardMapper.update(merchantAccessCardDO, WrappersFactory.updateWithNullField(merchantAccessCardDO).eq(MerchantAccessCardDO::getAccessId,merchantAccessInfoDO.getId()));
        if (CollectionUtils.isNotEmpty(merchantAccessCertInfoList)) {
            // 证件信息 先删 再加
            merchantAccessCertInfoMapper.delete(buildCertInfoWrapper(merchantAccessInfoDO.getId()));
            merchantAccessCertInfoMapper.insertBatch(merchantAccessCertInfoList);
        }
        merchantAccessBusinessMapper.update(merchantAccessBusinessDO,WrappersFactory.updateWithNullField(merchantAccessBusinessDO).eq(MerchantAccessBusinessDO::getAccessId,merchantAccessInfoDO.getId()));
        return merchantAccessInfoDO.getId();
    }

    @Override
    public MerchantAccessDto domainDetail(Long id) {
        MerchantAccessInfoDO merchantAccessInfoDO = merchantAccessInfoMapper.selectById(id);
        if (merchantAccessInfoDO == null) {
            return null;
        }
        List<MerchantAccessCertInfoDO> merchantAccessCertList = merchantAccessCertInfoMapper.selectList(buildCertInfoWrapper(id));
        MerchantAccessLicenseDO merchantAccessLicenseDO = merchantAccessLicenseMapper.selectOne(buildLicenseWrapper(id));
        MerchantAccessCardDO merchantAccessCardDO = merchantAccessCardMapper.selectOne(buildCardWrapper(id));
        MerchantAccessBusinessDO merchantAccessBusinessDO = merchantAccessBusinessMapper.selectOne(buildBusinessWrapper(id));
        MerchantAccessDto merchantAccessDto = new MerchantAccessDto();
        merchantAccessDto.setMerchantAccessInfo(merchantAccessInfoDO);
        merchantAccessDto.setMerchantAccessLicense(merchantAccessLicenseDO);
        merchantAccessDto.setMerchantAccessCard(merchantAccessCardDO);
        merchantAccessDto.setMerchantAccessBusiness(merchantAccessBusinessDO);
        if (CollectionUtils.isEmpty(merchantAccessCertList)) {
            return merchantAccessDto;
        }
        Map<Integer, List<MerchantAccessCertInfoDO>> merchantAccessCertMap = merchantAccessCertList.stream()
                .collect(Collectors.groupingBy(merchantAccessCertInfoDO -> merchantAccessCertInfoDO.getType()));
        List<MerchantAccessCertInfoDO> legalList = merchantAccessCertMap.get(MerchantEnum.CERT_INFO_TYPE.LEGAL.getCode());
        List<MerchantAccessCertInfoDO> contactList = merchantAccessCertMap.get(MerchantEnum.CERT_INFO_TYPE.CONTACT.getCode());
        List<MerchantAccessCertInfoDO> controllerList = merchantAccessCertMap.get(MerchantEnum.CERT_INFO_TYPE.CONTROLLER.getCode());
        List<MerchantAccessCertInfoDO> benefitList = merchantAccessCertMap.get(MerchantEnum.CERT_INFO_TYPE.BENEFIT.getCode());
        List<MerchantAccessCertInfoDO> shareholderList = merchantAccessCertMap.get(MerchantEnum.CERT_INFO_TYPE.SHAREHOLDER.getCode());
        if (CollectionUtils.isNotEmpty(legalList)) {
            merchantAccessDto.setMerchantAccessLegal(legalList.get(0));
        }
        if (CollectionUtils.isNotEmpty(contactList)) {
            merchantAccessDto.setMerchantAccessContact(contactList.get(0));
        }
        if (CollectionUtils.isNotEmpty(controllerList)) {
            merchantAccessDto.setMerchantAccessController(controllerList.get(0));
        }
        if (CollectionUtils.isNotEmpty(benefitList)) {
            merchantAccessDto.setMerchantAccessBenefitList(benefitList);
        }
        if (CollectionUtils.isNotEmpty(shareholderList)) {
            merchantAccessDto.setMerchantAccessShareholderList(shareholderList);
        }
        return merchantAccessDto;
    }

    @Override
    public MerchantAccessInfoDO detail(Long id) {
        return merchantAccessInfoMapper.selectById(id);
    }

    @Override
    public MerchantAccessInfoDO queryByRequestId(String requestId) {
        return merchantAccessInfoMapper.selectOne(MerchantAccessInfoDO::getRequestId, requestId);
    }

    @Override
    public void updateStatus(Long id, MerchantEnum.ACCESS_STATUS accessStatus, String remark) {
        MerchantAccessInfoDO merchantAccessInfoDO = new MerchantAccessInfoDO();
        merchantAccessInfoDO.setId(id);
        merchantAccessInfoDO.setStatus(accessStatus.getCode());
        merchantAccessInfoDO.setRemark(remark);
        log.info("updateStatus json:{}", JSONUtil.toJsonStr(merchantAccessInfoDO));
        merchantAccessInfoMapper.updateById(merchantAccessInfoDO);

    }

    @Override
    public void updateAccessInfo(MerchantAccessInfoDO merchantAccessInfoDO, List<MerchantAccessSignLink> signLinks) {
        if (!CollectionUtils.isEmpty(signLinks)) {
            MerchantAccessBusinessDO merchantAccessBusinessDO = new MerchantAccessBusinessDO();
            merchantAccessBusinessDO.setSignLink(JsonUtils.toJsonString(signLinks));

            merchantAccessBusinessMapper.update(merchantAccessBusinessDO, buildBusinessWrapper(merchantAccessInfoDO.getId()));
        }
        merchantAccessInfoMapper.updateById(merchantAccessInfoDO);
        String msg = "";
        Integer accessStatus = merchantAccessInfoDO.getStatus();
        if(accessStatus == null){
            return;
        }
//        if (accessStatus == 5) msg = "平台审核中";
//        if (accessStatus == 6) msg = "待签约";
//        if (accessStatus == 7) msg = "签约中";
//        if (accessStatus == 8) msg = "待配置";
        if (accessStatus == 9) msg = "配置中";
        if (accessStatus == 10) msg = "审核完成";
        if (StringUtils.hasText(msg))
            merchantAccessLogService.save(merchantAccessInfoDO.getId(), MerchantEnum.MERCHANT_LOG_TYPE.ACCESS, "机构审核", msg);
    }

    @Override
    public void updateSignlinks(Long id, List<MerchantAccessSignLink> signLinks) {
        if (!CollectionUtils.isEmpty(signLinks)) {
            MerchantAccessBusinessDO merchantAccessBusinessDO = new MerchantAccessBusinessDO();
            merchantAccessBusinessDO.setSignLink(JsonUtils.toJsonString(signLinks));
            merchantAccessBusinessMapper.update(merchantAccessBusinessDO, buildBusinessWrapper(id));
        }
    }

    @Override
    public void chanelCall(MerchantAccessCallDto merchantAccessCallDto) {
        MerchantAccessInfoDO merchantAccessInfoDO = merchantAccessCallDto.getMerchantAccessInfoDO();
        PayChannelRequestDO payChannelRequestDO = merchantAccessCallDto.getPayChannelRequestDO();
        payChannelRequestDO.setRelationId(merchantAccessInfoDO.getId().toString());
        merchantAccessInfoMapper.updateById(merchantAccessInfoDO);
        if (payChannelRequestDO.getId() == null) {
            payChannelService.saveRequest(payChannelRequestDO, PayEnums.CHANNEL_REQUEST_TYPE.MERCHANT_ACCESS);
        }
    }

    @Override
    public void delete(Long id) {
        merchantAccessInfoMapper.deleteById(id);
    }

    @Override
    public MerchantAccessInfoDO queryByMchOrderNo(String sn, String mchOrderNo) {
        return merchantAccessInfoMapper.selectOne(MerchantAccessInfoDO::getSn, sn, MerchantAccessInfoDO::getMchOrderNo, mchOrderNo);
    }

    @Override
    public MerchantAccessDto domainDetailByRequestId(String requestId) {
        MerchantAccessInfoDO merchantAccessInfoDO = queryByRequestId(requestId);
        if (merchantAccessInfoDO == null) {
            return null;
        }
        return domainDetail(merchantAccessInfoDO.getId());
    }

    @Override
    public MerchantAccessInfoDO queryBySubMchId(String subMchId) {
        return merchantAccessInfoMapper.selectOne(MerchantAccessInfoDO::getSubMchId, subMchId);
    }

    /**
     * 查询条件封装
     * 
     * @param merchantAccessInfoPageQueryDto
     * @return
     */
    QueryWrapper<MerchantAccessInfoDO> buildInfoWrapper(MerchantAccessInfoPageQueryDto merchantAccessInfoPageQueryDto) {
        filterSn(merchantAccessInfoPageQueryDto);
        QueryWrapperX<MerchantAccessInfoDO> queryWrapper = new QueryWrapperX<>();
        queryWrapper.eq("a.delete_flag", CommonEnum.YES_NO_TYPE.NO.getCode());
        queryWrapper.likeIfPresent("a.sn", merchantAccessInfoPageQueryDto.getLikeSn());
        queryWrapper.eqIfPresent("a.sn", merchantAccessInfoPageQueryDto.getSn());
        queryWrapper.eqIfPresent("contact.name", merchantAccessInfoPageQueryDto.getContactName());
        queryWrapper.inIfPresent("a.sn", merchantAccessInfoPageQueryDto.getSnList());
        queryWrapper.likeIfPresent("a.sub_mch_id", merchantAccessInfoPageQueryDto.getSubMchId());
        queryWrapper.eqIfPresent("a.status", merchantAccessInfoPageQueryDto.getStatus());
        queryWrapper.likeIfPresent("a.provider_code", merchantAccessInfoPageQueryDto.getProviderCode());
        queryWrapper.likeIfPresent("a.name", merchantAccessInfoPageQueryDto.getName());
        queryWrapper.likeIfPresent("bus.short_name", merchantAccessInfoPageQueryDto.getShortName());
        queryWrapper.likeIfPresent("contact.phone", merchantAccessInfoPageQueryDto.getContactPhone());
        queryWrapper.likeIfPresent("a.request_id", merchantAccessInfoPageQueryDto.getRequestId());
        queryWrapper.likeIfPresent("a.request_id", merchantAccessInfoPageQueryDto.getMchOrderNo());
        queryWrapper.eqIfPresent("a.channel_code", merchantAccessInfoPageQueryDto.getChannelCode());
        queryWrapper.geIfPresent("a.create_time", merchantAccessInfoPageQueryDto.getStartQueryTime());
        queryWrapper.leIfPresent("a.create_time", merchantAccessInfoPageQueryDto.getEndQueryTime());
        // queryWrapper.last(StringUtils.hasText(merchantAccessInfoPageQueryDto.getAgentCode()),"info.agent_code
        // like %'"+merchantAccessInfoPageQueryDto.getAgentCode()+"'%");
        queryWrapper.likeIfPresent("info.super_agent", merchantAccessInfoPageQueryDto.getSuperAgent());
        return queryWrapper;
    }

    /**
     * 查询条件封装
     *
     * @param merchantAccessInfoPageQueryDto
     * @return
     */
    LambdaQueryWrapper<MerchantAccessInfoDO> buildInfoWrapperX(MerchantAccessInfoPageQueryDto merchantAccessInfoPageQueryDto) {
        filterSn(merchantAccessInfoPageQueryDto);
        LambdaQueryWrapperX<MerchantAccessInfoDO> queryWrapper = new LambdaQueryWrapperX<>();
        queryWrapper.likeIfPresent(MerchantAccessInfoDO::getSn, merchantAccessInfoPageQueryDto.getLikeSn());
        queryWrapper.eqIfPresent(MerchantAccessInfoDO::getSn, merchantAccessInfoPageQueryDto.getSn());
        queryWrapper.inIfPresent(MerchantAccessInfoDO::getId, merchantAccessInfoPageQueryDto.getAccessIdList());
        queryWrapper.likeIfPresent(MerchantAccessInfoDO::getSubMchId, merchantAccessInfoPageQueryDto.getSubMchId());
        queryWrapper.inIfPresent(MerchantAccessInfoDO::getSubMchId, merchantAccessInfoPageQueryDto.getSubMchIdList());
        queryWrapper.eqIfPresent(MerchantAccessInfoDO::getStatus, merchantAccessInfoPageQueryDto.getStatus());
        queryWrapper.likeIfPresent(MerchantAccessInfoDO::getProviderCode, merchantAccessInfoPageQueryDto.getProviderCode());
        queryWrapper.likeIfPresent(MerchantAccessInfoDO::getName, merchantAccessInfoPageQueryDto.getName());
        queryWrapper.likeIfPresent(MerchantAccessInfoDO::getRequestId, merchantAccessInfoPageQueryDto.getRequestId());
        queryWrapper.eqIfPresent(MerchantAccessInfoDO::getChannelCode, merchantAccessInfoPageQueryDto.getChannelCode());
        return queryWrapper;
    }

    /**
     * 查询条件封装
     * 
     * @param accessId
     * @return
     */
    LambdaQueryWrapper<MerchantAccessCertInfoDO> buildCertInfoWrapper(Long accessId) {
        LambdaQueryWrapperX<MerchantAccessCertInfoDO> queryWrapper = new LambdaQueryWrapperX<>();
        queryWrapper.eqIfPresent(MerchantAccessCertInfoDO::getAccessId, accessId);
        return queryWrapper;
    }

    /**
     * 查询条件封装
     * 
     * @param accessId
     * @return
     */
    LambdaQueryWrapper<MerchantAccessLicenseDO> buildLicenseWrapper(Long accessId) {
        LambdaQueryWrapperX<MerchantAccessLicenseDO> queryWrapper = new LambdaQueryWrapperX<>();
        queryWrapper.eqIfPresent(MerchantAccessLicenseDO::getAccessId, accessId);
        return queryWrapper;
    }

    /**
     * 查询条件封装
     * 
     * @param accessId
     * @return
     */
    LambdaQueryWrapper<MerchantAccessCardDO> buildCardWrapper(Long accessId) {
        LambdaQueryWrapperX<MerchantAccessCardDO> queryWrapper = new LambdaQueryWrapperX<>();
        queryWrapper.eqIfPresent(MerchantAccessCardDO::getAccessId, accessId);
        return queryWrapper;
    }

    /**
     * 查询条件封装
     *
     * @param accessId
     * @return
     */
    LambdaQueryWrapper<MerchantAccessBusinessDO> buildBusinessWrapper(Long accessId) {
        LambdaQueryWrapperX<MerchantAccessBusinessDO> queryWrapper = new LambdaQueryWrapperX<>();
        queryWrapper.eqIfPresent(MerchantAccessBusinessDO::getAccessId, accessId);
        return queryWrapper;
    }

}
